/**
 * \file kernel/basic_utils.cpp
 */

#include <dodo_plot/kernel/basic_utils.h>
#include <dodo_plot/kernel/basic_elements.h>

#include <cairomm/cairomm.h>

namespace dodo_plot
{

void set_cr_color(Context_p& cr, const Color& color)
{
	cr->set_source_rgba(color.r(), color.g(), color.b(), color.a());
}

Pos_Projection::Pos_Projection()
	: x_scale_(0), y_scale_(0), x_offset_(0), y_offset_(0)
{ }

Pos_Projection::Pos_Projection(const Position& given_pos, double local_w, double local_h)
		: x_offset_(given_pos.left),
		y_offset_(given_pos.top)
{
	x_scale_ = (local_w == 0) ?
	           1.0 :
	           given_pos.width() / local_w;

	y_scale_ = (local_h == 0) ?
	           1.0 :
	           given_pos.height() / local_h;
}

Pos_Projection::Pos_Projection(const Position& given_pos, const Position& local_pos)
{
	x_scale_ = (local_pos.width() == 0) ?
	           1.0 :
	           given_pos.width() / local_pos.width();
	y_scale_ = (local_pos.height() == 0) ?
	           1.0 :
	           given_pos.height() / local_pos.height();

	x_offset_ = given_pos.left - local_pos.left * x_scale_;
	y_offset_ = given_pos.top - local_pos.top * y_scale_;
}

}


